/*
	LOAD REQUEST VIA XML
*/

require('./common');

exports.load = function(req, res){
	var tblName = req.params.tblname;
	var id = req.params.id;
	generateXML(res,tblName,id);
}

function generateXML(res, tblName, id){
	var xmlData='';
	var fieldName;
	var fieldValue;
	
	var strSQL = "SELECT * FROM " + tblName + " WHERE ID = '" + id + "' ";
	conn.query(strSQL, function(err, results, fields){
		if(err) throw err;
		
			res.charset = 'UTF-8';
			res.header('Content-Type', 'text/xml');
			
			
			for (var index in results) {
				xmlData += "<request>";
				for (var findex in fields) {
				
					var sqlResult = results[index];
					var fieldName = fields[findex].name;
					var fieldValue = sqlResult[fieldName];
						
					xmlData += "<" + fieldName + ">" + fieldValue + "</" + fieldName + ">";
				}
			
				xmlData += "</request>";
			}	
			
			res.send(xmlData);
	});

}